﻿Imports System.Data
Imports System.Data.SqlClient

Imports BE = BusinessEntities
Public Class AdicionalesDAO
    Dim conexion As SqlConnection
    Dim da As SqlDataAdapter
    Dim str_error As String
    Dim bool_resultado As Boolean
    Dim cmd As SqlCommand

    Dim cn As New Conexion
    Public Function InsertarAdicional(ByVal objeto As BE.AdicionalesDTO) As Boolean

        Dim cn As New Conexion
        Try
            conexion = cn.Conectar

            cmd = New SqlCommand("SP_INSERT_ADICIONALES", conexion)

            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add(New SqlParameter("@NRO_REQ", SqlDbType.Int))
            cmd.Parameters("@NRO_REQ").Direction = ParameterDirection.Input
            cmd.Parameters("@NRO_REQ").Value = objeto.Numero_Requisicion

            cmd.Parameters.Add(New SqlParameter("@COD_GAS", SqlDbType.Int))
            cmd.Parameters("@COD_GAS").Direction = ParameterDirection.Input
            cmd.Parameters("@COD_GAS").Value = objeto.Codigo_gasto

            cmd.Parameters.Add(New SqlParameter("@MOT_ADD", SqlDbType.VarChar, 100))
            cmd.Parameters("@MOT_ADD").Direction = ParameterDirection.Input
            cmd.Parameters("@MOT_ADD").Value = objeto.Motivo_Adicional

            cmd.Parameters.Add(New SqlParameter("@FEC_INI", SqlDbType.DateTime))
            cmd.Parameters("@FEC_INI").Direction = ParameterDirection.Input
            cmd.Parameters("@FEC_INI").Value = objeto.Fecha_Inicio

            cmd.Parameters.Add(New SqlParameter("@FEC_FIN", SqlDbType.DateTime))
            cmd.Parameters("@FEC_FIN").Direction = ParameterDirection.Input
            cmd.Parameters("@FEC_FIN").Value = objeto.Fecha_Fin

            cmd.Parameters.Add(New SqlParameter("@NRO_PER", SqlDbType.Int))
            cmd.Parameters("@NRO_PER").Direction = ParameterDirection.Input
            cmd.Parameters("@NRO_PER").Value = objeto.Numero_Personas

            cmd.Parameters.Add(New SqlParameter("@NRO_DIA", SqlDbType.Int))
            cmd.Parameters("@NRO_DIA").Direction = ParameterDirection.Input
            cmd.Parameters("@NRO_DIA").Value = objeto.Numero_Dias

            cmd.Parameters.Add(New SqlParameter("@CST_PER", SqlDbType.Decimal))
            cmd.Parameters("@CST_PER").Direction = ParameterDirection.Input
            cmd.Parameters("@CST_PER").Value = objeto.Costo_Persona

            cmd.Parameters.Add(New SqlParameter("@OBS_ADD", SqlDbType.VarChar, 100))
            cmd.Parameters("@OBS_ADD").Direction = ParameterDirection.Input
            cmd.Parameters("@OBS_ADD").Value = objeto.Observaciones_Add

            cmd.Parameters.Add(New SqlParameter("@SUB_TOT", SqlDbType.Decimal))
            cmd.Parameters("@SUB_TOT").Direction = ParameterDirection.Input
            cmd.Parameters("@SUB_TOT").Value = objeto.Sub_Total

            conexion.Open()

            cmd.ExecuteNonQuery()

        Catch ex As Exception
            str_error = ex.Message
        Finally

            If conexion.State = ConnectionState.Open Then conexion.Close()
            conexion.Dispose()
            cmd.Dispose()
            cn = Nothing

        End Try

        Return bool_resultado

    End Function
    Public Function CapturaError() As String
        Return str_error
    End Function
End Class
